package data_visualization;

import weka.core.Attribute;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.Normalize;


public class data_plot {
    public static void printAttribute(Instances instances)
    {
        int numOfAttributes = instances.numAttributes();
        for(int i = 0; i < numOfAttributes ;++i)
        {
            Attribute attribute = instances.attribute(i);
            System.out.print(attribute.name() + " ");
        }
        System.out.println();
        //打印实例
        int numOfInstance = instances.numInstances();
        for(int i = 0; i < numOfInstance; ++i)
        {
            Instance instance = instances.instance(i);
            System.out.print(instance.toString() + " "+ "\n");
        }
    }
    public static void main(String[] args) throws Exception {
        DataSource source = new DataSource("/home/tang/appdata/weka-3-8-4/data/iris.arff"); //获取数据源
        Instances instances = source.getDataSet();//导入数据

//归一化
        System.out.println("Step 2. 归一化...");
        Normalize norm = new Normalize();//建立一个归一化filter
        norm.setInputFormat(instances);//为filter导入数据
        Instances newInstances = Filter.useFilter(instances, norm);//得到归一化后的数据
        printAttribute(newInstances);
    }
}
